﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Control="clr-namespace:WPNextTools.NControls"
                    xmlns:Helper="clr-namespace:WPNextTools.NHelper"
                    xmlns:System="clr-namespace:System;assembly=mscorlib"
                    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">

    <Style TargetType="Control:PullDownToRefreshPanel">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="PullingDownTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock Margin="0,16,0,0"
                               Text="下拉刷新..."
                               TextAlignment="Center" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ReadyToReleaseTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock Margin="0,16,0,0"
                               Text="释放加载数据..."
                               TextAlignment="Center" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <!--
            <Setter Property="RefreshingTemplate">
            <Setter.Value>
            <DataTemplate>
            <ProgressBar Margin="0,4,0,4" IsIndeterminate="True" />
            </DataTemplate>
            </Setter.Value>
            </Setter>
        -->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Control:PullDownToRefreshPanel">
                    <StackPanel x:Name="PullDownContainer" HorizontalAlignment="Stretch">
                        <StackPanel.Resources>
                            <Helper:NegativeValueConverter x:Key="NegativeValueConverter" />
                        </StackPanel.Resources>
                        <StackPanel x:Name="PullingDownPanel"
                                    Height="{TemplateBinding PullDistance}"
                                    Margin="{Binding PullDistance,
                                                     RelativeSource={RelativeSource TemplatedParent},
                                                     Converter={StaticResource NegativeValueConverter},
                                                     ConverterParameter=Bottom}"
                                    Background="{TemplateBinding Background}"
                                    Opacity="{TemplateBinding PullFraction}"
                                    Visibility="Collapsed">
                            <ContentPresenter ContentTemplate="{TemplateBinding PullingDownTemplate}" />
                        </StackPanel>
                        <StackPanel x:Name="ReadyToReleasePanel"
                                    Height="{TemplateBinding PullDistance}"
                                    Margin="{Binding PullDistance,
                                                     RelativeSource={RelativeSource TemplatedParent},
                                                     Converter={StaticResource NegativeValueConverter},
                                                     ConverterParameter=Bottom}"
                                    Background="{TemplateBinding Background}"
                                    Visibility="Collapsed">
                            <ContentPresenter ContentTemplate="{TemplateBinding ReadyToReleaseTemplate}" />
                        </StackPanel>
                        <!--
                            <StackPanel x:Name="RefreshingPanel"
                            Background="{TemplateBinding Background}"
                            Visibility="Collapsed">
                            <ContentPresenter ContentTemplate="{TemplateBinding RefreshingTemplate}" />
                            </StackPanel>
                        -->
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="ActivityStates">
                                <VisualState x:Name="Inactive" />
                                <VisualState x:Name="PullingDown">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PullingDownPanel" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="ReadyToRelease">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ReadyToReleasePanel" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Refreshing">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RefreshingPanel" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>